let i = 1;

function yanzheng() {
    let nameInput = document.getElementById("nameInput");
    let messageUI = document.getElementById("messageUI");
    if (nameInput.value.length < 5) {
        if (i > 3) {
            alert("曾冬诚 230320204018");
            return;
        }
        if (i == 1) {
            messageUI.style.backgroundColor = "green";
        } else if (i == 2) {
            messageUI.style.backgroundColor = "yellow";
        } else if (i == 3) {
            messageUI.style.backgroundColor = "blue";
        }
        messageUI.textContent = "用户名不能小于5,你还有的机会次数是:" + (3 - i);
        messageUI.className = "cuowuUI";
        i++;
    } else {
        messageUI.textContent = "填写正确";
        messageUI.className = "OkUI";
    }
}
function login() {
    const nameInput = document.getElementById("nameinput");
    const pswdInput = document.getElementById("pswdinput");

    if (nameInput.value.length < 2) {
        alert("你的用户名太短了");
        return;
    }
    if (nameInput.value.includes("犯罪")) {
        alert("你的用户名太奇葩了");
        return;
    }
    // 调用后端的接口，进行 用户名和密码验证
    fetch("https://study.godoai.com/api/user/login/" + nameInput.value + "/" + pswdInput.value)
        .then(resp => resp.json())
        .then(data => {
            if (data.Code == 1000) {
                console.log("token是:" + data.Title);
                sessionStorage.setItem("token", data.Title);
                window.location.href = "./userlist.html";
            } else {
                alert("登录失败");
            }
        });
}

function register() {
    alert("新用户注册功能暂未开放");
}